﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace format_proj
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (DialogResult.OK == ofd.ShowDialog())
            {
                string path = ofd.FileName;
                try
                {
                    System.Diagnostics.Process exep = new System.Diagnostics.Process();
                    exep.StartInfo.FileName = @"Astyle.exe";
                    exep.StartInfo.Arguments = @"--style=allman -p " + path;
                    exep.StartInfo.CreateNoWindow = true;
                    exep.StartInfo.UseShellExecute = true;
                    exep.Start();
                    exep.WaitForExit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    MessageBox.Show("format complete");
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fd = new FolderBrowserDialog();
            if(fd.ShowDialog()==DialogResult.OK)
            {
                string path = fd.SelectedPath;
                path = path + @"/*.cpp,*.c,*.h";
                try
                {
                    System.Diagnostics.Process exep = new System.Diagnostics.Process();
                    exep.StartInfo.FileName = @"Astyle.exe";
                    exep.StartInfo.Arguments = @"--style=allman -p --recursive " + path;
                    exep.StartInfo.CreateNoWindow = true;
                    exep.StartInfo.UseShellExecute = true;
                    exep.Start();
                    exep.WaitForExit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    MessageBox.Show("format complete");
                }
            }
        }
    }
}
